import axios from "axios";
import uuidv1 from "uuid/v1";
let mixin = {
  props: {},
  mounted() {},
  data() {
    return {
      gongreds: [],
      gongrecolor: {
        "zhengzhou-model-0-yes.json": "#b399ffb3",
        "zhengzhou-model-0-no.json": "#c0c0c0b3",
        "zhengzhou-model-1-yes.json": "#00ffffb3",
        "zhengzhou-model-1-no.json": "#c0c0c0b3"
      },

      pointericon: {
        隔压站: "geyazhan-01.png",
        燃气锅炉房: "guolufang-01.png",
        热电厂: "redianchang-01.png"
      },

      showdetailpointer: false,
      showteshupointer: false,

      showheight: 9000,
      _odlines: {}
    };
  },
  watch: {},
  methods: {
    //初始化方法
    gongre() {
      let _this = this;
      var viewer = this._earth.czm.viewer;
      let geos = [
        "zhengzhou-model-0-yes.json",
        "zhengzhou-model-0-no.json",
        "zhengzhou-model-1-yes.json",
        "zhengzhou-model-1-no.json"
      ];

      // geos.map(item => {
      //   _this._earth.sceneTree.root.children.push({
      //     ref: item,
      //     czmObject: {
      //       xbsjType: "XbsjGeoJSON",
      //       xbsjGuid: "c17db3bb-ef93-452a-964a-3a579e63787b",
      //       url: "http://124.70.158.145:9997/zz/" + item
      //     }
      //   });
      // });
      // geos.map(item => {

      //   let tile = _this._earth.sceneTree.$refs[item].czmObject;

      // });

      // geos.map(item => {
      //   var promise = Cesium.GeoJsonDataSource.load("/geojson/" + item);
      //   promise.then(function(dataSource) {
      //     // viewer.dataSources.add(dataSource);
      //     var entities = dataSource.entities.values;

      //     for (var o = 0; o < entities.length; o++) {
      //       let entity = entities[o];

      //       if (entity.id.split(".")[0] == "pipeline") {
      //         console.log(entity);
      //         entity.polyline.width = 10; //添加默认样式
      //         entity.polyline.material = new Cesium.PolylineGlowMaterialProperty(
      //           {
      //             glowPower: 0.1, //一个数字属性，指定发光强度，占总线宽的百分比。
      //             color: Cesium.Color.fromCssColorString("#dddd")
      //           }
      //         );
      //       }
      //     }
      //   });
      // });

      this.loadData1()

    },

    addodlines(data, timeDuration, color) {
      this._odlines = new XE.Obj.ODLines(this._earth);
      this._odlines.translucentPass = false;
      this._odlines.color = color;
      this._odlines.data = data;
      this._odlines.timeDuration = timeDuration;
      this._odlines.playing = true;
    },

    loadData1() {
      let _this = this
      let geos = [
        "zhengzhou-model-0-yes.json",
        "zhengzhou-model-0-no.json",
        "zhengzhou-model-1-yes.json",
        "zhengzhou-model-1-no.json"
      ];

      geos.map(item => {
        var promise = Cesium.GeoJsonDataSource.load("/geojson/" + item);
        promise.then(function(dataSource) {
          var entities = dataSource.entities.values;
          var timeDuration = 10.0;
          var moveBaseDuration = 0.0;
          var busLines = [];

          for (var o = 0; o < entities.length; o++) {
            let entity = entities[o];
            if (entity.id.split(".")[0] == "pipeline") {
              // if (!entity.polyline.positions._value) {
              //   continue
              // }

              var points = [];
              entity.polyline.positions._value.map(item => {
                points.push([
                  Cesium.Cartographic.fromCartesian(item).longitude,
                  Cesium.Cartographic.fromCartesian(item).latitude
                ]);
              });

              busLines.push({
                positions: points,
                color: [
                  (Math.random() * 0.5 + 0.5) * 1,
                  (Math.random() * 0.8 + 0.2) * 1,
                  0.0,
                  250
                ],
                width: 1.0,
                startTime: timeDuration * Math.random(),
                duration: moveBaseDuration + 1.0 * Math.random()
              });
            }
          }
          _this.addodlines(busLines, timeDuration, [1, 1, 1, 3]);
        });
      });
    }
  }
};

export default mixin;
